/**
 * New node file
 */

var confirmFriend = new Function();
confirmFriend.prototype = {
	init: function(req, res){
		this.req = req;
		this.res = res;
		switch (req.method) {
			case 'POST': this.post(req, res); break;
			default: this.other(req, res); break;
		}
	},
	post: function(req, res){
		var id = req.body.id;
		var userId1 = req.body.userId1;
		var userId2 = req.body.userId2;
		var cfService = new (Services('confirmFriend'))(id, userId1, userId2, {
			success: function(data){
				res.send(JSON.stringify({ success: true, data: data }));
				res.end();
			},
			error: function(code, message){
				throw new Exception(code, message, function(){
					res.send(this.toString());
					res.end();
				});
			}
		});
	},
	other: function(req, res){
		res.writeHead(404, {
			'Content-Type': 'text/plain',
			'Trailer': 'Content-MD5'
		});
		res.end();
	}
};

module.exports = confirmFriend;